/**
 * Copyright [2020] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.callcenter.admin.web;


import com.hyts.callcenter.base.CallCenterRequest;
import com.hyts.callcenter.base.CallCenterResponse;
import com.hyts.callcenter.model.dto.CallTaskDTO;
import com.hyts.callcenter.schema.CallTaskSchemaApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @project-name:callcenter
 * @package-name:com.hyts.callcenter.admin.web
 * @author:LiBo/Alex
 * @create-date:2021-12-04 10:59 下午
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/callTask")
public class CallTaskController {


    @DubboReference(version = "1.0.0")
    private CallTaskSchemaApi callTaskSchemaApi;



    @PostMapping("/start")
    public CallCenterResponse start(@RequestBody CallTaskDTO callTaskDTO){
        try {
            CallCenterResponse response = callTaskSchemaApi.startTask(new CallCenterRequest(callTaskDTO.getTaskId()));
            log.info("执行成功：{}",response);
            return response;
        } catch (Exception e) {
            log.error("执行失败",e);
            return CallCenterResponse.failure("执行失败！");
        }
    }



    @PostMapping("/stop")
    public CallCenterResponse stop(@RequestBody CallTaskDTO callTaskDTO){
        return callTaskSchemaApi.stopTask(new CallCenterRequest(callTaskDTO.getTaskId()));
    }


}
